\subsection{Geometry of trigonometric functions}
Recall that given any two vectors \(\vb x\) and \(\vb y\) in \(\mathbb R^2\), we can define the dot (scalar) product by
\[
	\vb x \cdot \vb y = (x_1, x_2) \cdot (y_1, y_2) = x_1y_1 + x_2y_2
\]
By the Cauchy--Schwarz inequality, we have
\[
	\abs{\vb x \cdot \vb y} \leq \norm{\vb x} \norm{\vb y}
\]
where we define the Euclidean norm in the normal way.
Thus, for \(\vb x \neq 0\), \(\vb y \neq 0\), we have
\[
	-1 \leq \frac{\vb x \cdot \vb y}{\norm{\vb x} \norm{\vb y}} \leq 1
\]
We now define the angle between two vectors \(\vb x\) and \(\vb y\) as exactly the unique number \(\theta \in [0, \pi]\) such that
\[
	\cos\theta = \frac{\vb x \cdot \vb y}{\norm{\vb x} \norm{\vb y}}
\]

\subsection{Hyperbolic functions}
We define the functions \(\cosh\) and \(\sinh\) as follows.
\[
	\cosh z = \frac{1}{2}\qty(e^z + e^{-z})
\]
\[
	\sinh z = \frac{1}{2}\qty(e^z - e^{-z})
\]
Hence
\[
	\cosh z = \cos(iz);\quad \sinh z = -i\sin(iz)
\]
We can then show that
\[
	\dv{z} \cosh z = \sinh z;\quad \dv{z} \sinh z = \cosh z
\]
and further,
\[
	\cosh^2 z - \sinh^2 z \equiv 1
\]

\subsection{Defining the Riemann integral}
\begin{definition}
	A \textit{dissection} or \textit{partition} \(\mathcal D\) of \([a, b]\) is a finite subset of \([a, b]\) containing the end points \(a\) and \(b\).
	We write
	\[
		\mathcal D = \{ x_0, x_1, \dots, x_n \}
	\]
	with \(a = x_0 < x_1 < \dots < x_{n-1} < x_n = b\).
\end{definition}
\begin{definition}
	We define the \textit{upper sum} of a bounded function \(f\) associated with a partition \(\mathcal D\) by
	\[
		S(f, \mathcal D) = \sum_{j=1}^n (x_j - x_{j-1}) \sup_{x \in [x_{j-1}, x_j]} f(x)
	\]
	The \textit{lower sum} is defined similarly,
	\[
		s(f, \mathcal D) = \sum_{j=1}^n (x_j - x_{j-1}) \inf_{x \in [x_{j-1}, x_j]} f(x)
	\]
\end{definition}
Clearly then \(S \geq s\) for all \(\mathcal D\).
\begin{lemma}
	If \(\mathcal D\) and \(\mathcal D'\) are dissections with \(\mathcal D' \supseteq \mathcal D\) (\(\mathcal D'\) is a refinement of \(\mathcal D\)), then
	\[
		S(f, \mathcal D) \underset{(\mathrm{i})}{\geq} S(f, \mathcal D') \underset{(\mathrm{ii})}{\geq} s(f, \mathcal D') \underset{(\mathrm{iii})}{\geq} s(f, \mathcal D)
	\]
\end{lemma}
\begin{proof}
	Inequality (ii) is obvious, we have already shown this to be true.
	Now, suppose \(\mathcal D'\) contains a single extra point \(y\) compared to \(\mathcal D\), where \(y \in (x_{r-1}, x_r)\).
	Clearly,
	\[
		\sup_{x \in [x_{r-1}, y]} f(x), \sup_{x \in [y, x_r]} f(x) \leq \sup_{x \in [x_{r-1}, x_r]}
	\]
	Then
	\[
		(x_r - x_{r-1}) \sup_{x \in [x_{r-1}, x_r]} f(x) \geq (y-x_{r-1}) \sup_{x \in [r_{r-1}, y]} f(x) + (x_r - y) \sup_{x \in [y, r]} f(x)
	\]
	Hence,
	\[
		S(f, \mathcal D) \geq S(f, \mathcal D')
	\]
	The same proof holds for inequality (iii), and inductively we can show that this works for any amount of extra points.
\end{proof}
\begin{lemma}
	If \(\mathcal D_1, \mathcal D_2\) are arbitrary dissections, then
	\[
		S(f, \mathcal D_1) \geq S(f, \mathcal D_1 \cup \mathcal D_2) \geq s(f, \mathcal D_1 \cup \mathcal D_2) \geq s(f, \mathcal D_2)
	\]
	In particular, \(S(f, \mathcal D_1) \geq s(f, \mathcal D_2)\).
\end{lemma}
\begin{proof}
	Let \(\mathcal D' = \mathcal D_1 \cup \mathcal D_2\), which is a refinement of both \(\mathcal D_1\) and \(\mathcal D_2\), and apply the previous lemma.
\end{proof}
\begin{definition}
	The \textit{upper integral} of \(f\) is
	\[
		I^\star(f) = \inf_{\mathcal D} S(f, \mathcal D)
	\]
	Note that such an integral always exists, since the upper sums are always bounded below by an arbitrary lower sum.
	Hence the infimum does indeed exist and is finite.
	Similarly,
	\[
		I_\star(f) = \sup_{\mathcal D} s(f, \mathcal D)
	\]
\end{definition}
Then by the lemmas above, \(I^\star(f) \geq I_\star(f)\), since \(S(f, \mathcal D_2) \geq s(f, \mathcal D_1)\) for arbitrary dissections \(\mathcal D_1\) and \(\mathcal D_2\).
\begin{definition}
	A bounded function \(f \colon [a, b] \to \mathbb R\) is (Riemann) integrable if \(I^\star(f) = I_\star(f)\).
	If this equality holds, we write
	\[
		\int_a^b f(x) \dd{x} = I^\star(f) = I_\star(f) = \int_a^b f
	\]
\end{definition}

\subsection{Determining integrability}
\begin{theorem}
	A function \(f \colon [a, b] \to \mathbb R\) is Riemann integrable if and only if given \(\varepsilon > 0\), there exists \(\mathcal D\) such that
	\[
		S(f, \mathcal D) - s(f, \mathcal D) < \varepsilon
	\]
\end{theorem}
\begin{proof}
	For every dissection \(\mathcal D\), we have that \(0 \leq I^\star(f) - I_\star(f) \leq S(f, \mathcal D) - s(f, \mathcal D)\).
	If the given condition holds, \(0 \leq I^\star(f) - I_\star(f) \leq S(f, \mathcal D) - s(f, \mathcal D) < \varepsilon\) for all \(\varepsilon > 0\).
	This immediately implies that \(f\) is Riemann integrable since the upper integral and the lower integral match.
	Conversely, if \(f\) is integrable, by the definition of the supremum and infimum, there are partitions \(\mathcal D_1\) and \(\mathcal D_2\) such that
	\[
		\int_a^b f - \frac{\varepsilon}{2} = I_\star(f) - \frac{\varepsilon}{2} < s(f, \mathcal D_1)
	\]
	Also,
	\[
		\int_a^b f + \frac{\varepsilon}{2} = I^\star(f) + \frac{\varepsilon}{2} > S(f, \mathcal D_2)
	\]
	From last lecture, we can use the fact that \(\mathcal D_1 \cup \mathcal D_2\) is a refinement of both \(\mathcal D_1\) and \(\mathcal D_2\) to show that
	\[
		S(f, \mathcal D_1 \cup \mathcal D_2) - s(f, \mathcal D_1 \cup \mathcal D_2) \leq S(f, \mathcal D_2) - s(f, \mathcal D_1)
	\]
	Now,
	\[
		S(f, \mathcal D_2) - s(f, \mathcal D_1) < \int_a^b f + \frac{\varepsilon}{2} - \int_a^b f + \frac{\varepsilon}{2} = \varepsilon
	\]
	as required.
\end{proof}

\subsection{Monotonic and continuous functions}
We can use this theorem to show that monotonic and continous functions are integrable.
Note that monotonic and continuous functions (defined on a closed interval) are always bounded.
\begin{theorem}
	Suppose a function \(f \colon [a, b] \to \mathbb R\) is monotonic.
	Then \(f\) is integrable.
\end{theorem}
\begin{proof}
	Suppose \(f\) is increasing.
	Then
	\[\sup_{x \in [x_{j-1} - x_j]} f(x) = f(x_j)\]
	and similarly
	\[\inf_{x \in [x_{j-1} - x_j]} f(x) = f(x_{j-1})\]
	Thus,
	\[
		S(f, \mathcal D) - s(f, \mathcal D) = \sum_{j=1}^n (x_j - x_{j-1}) \left[ f(x_j) - f(x_{j-1}) \right]
	\]
	Let us choose the dissection
	\[
		\mathcal D = \qty{ a, a + \frac{b-a}{n}, a + 2\frac{b-a}{n} + \dots + b }
	\]
	giving
	\[
		x_j = a + j\frac{b-a}{n}
	\]
	for \(0 \leq j \leq n\).
	In this case,
	\[
		S(f, \mathcal D) - s(f, \mathcal D) = \frac{b-a}{n} \sum_{j=1}^n \left[ f(x_j) - f(x_{j-1}) \right] = \frac{b-a}{n} \left[ f(b) - f(a) \right] \to 0
	\]
	so then using the above theorem, \(f\) is integrable.
\end{proof}
To prove an analogous result for continuous function, we must first prove the following lemma.
\begin{lemma}[Uniform Continuity]
	Suppose a function \(f \colon [a, b] \to \mathbb R\) is continuous.
	Then given \(\varepsilon > 0\), \(\exists \delta > 0\) such that if \(\abs{x-y} < \delta\), we have \(\abs{f(x) - f(y)} < \varepsilon\).
\end{lemma}
Note that in this lemma, we are saying that there exists such a \(\delta\) that works for \textit{every} pair of points within \(\delta\).
The definition of continuity only provides a \(\delta\) that depends on \(x\), so this is stronger than the definition of continuity, and this property does not hold for all continuous functions.
\begin{proof}
	Suppose there does not exist such a \(\delta\).
	Then there exists some \(\varepsilon > 0\) such that for all \(\delta > 0\) there exist \(x, y \in [a, b]\) such that \(\abs{x-y} < \delta\) but \(\abs{f(x) - f(y)} \geq \varepsilon\).
	Let \(\delta = \frac{1}{n}\).
	For this choice, we can find sequences \(x_n\) and \(y_n\) with \(\abs{x_n - y_n} < \frac{1}{n}\) but \(\abs{f(x_n) - f(y_n)} \geq \varepsilon\).
	By the Bolzano--Weierstrass theorem, since we are working in a closed bounded interval, the \(x_n\) and \(y_n\) have convergent subsequences that tend to \(c\) and \(d\).
	Then by the triangle inequality,
	\[
		\abs{y_{n_k} - c} \leq \abs{y_{n_k} - x_{n_k}} + \abs{x_{n_k} - c} \to 0
	\]
	So \(c = d\).
	But \(\abs{f(x_{n_k}) - f(y_{n_k})} \geq \varepsilon\), and by continuity as \(k \to \infty\), \(\abs{f(c) - f(c)} \geq \varepsilon\) which is a contradiction.
\end{proof}
\begin{theorem}
	Suppose a function \(f \colon [a, b] \to \mathbb R\) is continuous.
	Then \(f\) is integrable.
\end{theorem}
\begin{proof}
	We know that given \(\varepsilon > 0\), there exists \(\delta > 0\) such that \(\abs{x - y} < \delta \implies \abs{f(x) - f(y)} < \varepsilon\).
	So now, let
	\[
		\mathcal D = \qty{ a, a + \frac{b-a}{n}, a + 2\frac{b-a}{n} + \dots + b }
	\]
	where \(n\) is chosen large enough such that \(\frac{b-a}{n} < \delta\).
	Then, for any \(x, y \in [x_{j-1}, x_j]\), we have that \(\abs{f(x) - f(y)} < \varepsilon\).
	We can now write
	\[
		\max_{x \in [x_{j-1}, x_j]} f(x) - \min_{x \in [x_{j-1}, x_j]} f(x) = f(p) - f(q) < \varepsilon
	\]
	Therefore, the upper sums and lower sums differ by at most \((b-a)\varepsilon\).
	Hence, \(f\) is integrable.
\end{proof}

\subsection{Complicated integrable functions}
In principle, many functions that are not continuous or monotonic can be integrated using the Riemann integral.
For example, the function \(f\colon [0, 1] \to \mathbb R\) defined by
\[
	f(x) = \begin{cases}
		\frac{1}{q} & x = \frac{p}{q} \in (0, 1] \text{ in its lowest form } \\
		0           & \text{otherwise}
	\end{cases}
\]
is Riemann integrable.
We know that \(s(f, \mathcal D) = 0\) for all \(\mathcal D\), since any interval will contain irrational numbers.
We will show that given \(\varepsilon > 0\), there exists \(\mathcal D\) such that \(S(f, \mathcal D) < \varepsilon\).
If this is true, then this function \(f\) really is Riemann integrable, with \(\int f = 0\).
We will choose \(N \in \mathbb N\) such that \(\frac{1}{N} < \frac{\varepsilon}{2}\).
Then
\[
	S = \qty{ x \in [0, 1] \colon f(x) \geq \frac{1}{N} } = \qty{ \frac{p}{q} \colon 1 \leq q \leq N, 1 \leq p \leq q }
\]
This set \(S\) is a finite set, hence
\[
	S = \qty{ 0, t_1, \dots, t_R };\quad 0 < t_1 < \dots < t_R = 1
\]
Consider a dissection \(\mathcal D\) such that
\begin{enumerate}[(1)]
	\item Each \(t_k\) is in some interval \([x_{j-1}, x_j]\), and
	\item For all \(k\), the unique interval containing \(t_k\) has length at most \(\frac{\varepsilon}{2R}\).
\end{enumerate}
Such a dissection can certainly be constructed.
Then, in any interval that does not contain a \(t_k\), \(f\) in this interval is less than \(\frac{1}{N}\).
In any interval that does contain a \(t_k\), \(f \geq \frac{1}{N}\) but \(f < 1\) everywhere.
Since there are \(R\) such intervals, each of which with length \(\frac{\varepsilon}{2R}\), we have
\[
	S(f, \mathcal D) \leq \frac{1}{N} + \frac{\varepsilon}{2} < \varepsilon
\]

\subsection{Properties of Riemann integral}
Consider functions \(f\) and \(g\) which are bounded and integrable on \([a, b]\).
\begin{enumerate}[(1)]
	\item If \(f \leq g\) on \([a, b]\), then \(\int f \leq \int g\).
	\item \(f + g\) is integrable on \([a, b]\), and \(\int (f + g) = \int f + \int g\).
	\item For any constant \(k\), \(kf\) is integrable, and \(\int kf = k\int f\).
	\item \(\abs{f}\) is integrable, and \(\abs{\int f} \leq \int \abs{f}\).
	\item \(fg\) is integrable.
\end{enumerate}
\begin{proof}
	We will see proofs for some of these properties.
	\begin{enumerate}[(1)]
		\item If \(f \leq g\), then
		      \[
			      \int f = I^\star(f) \leq S(f, \mathcal D) \leq S(g, \mathcal D)
		      \]
		      Hence,
		      \[
			      \int f = I^\star(f) \leq I^\star(g) = \int g
		      \]
		\item We have
		      \[
			      \sup_{[x_{j-1}, x_j]} (f + g) \leq \sup_{[x_{j-1}, x_j]} f + \sup_{[x_{j-1}, x_j]} g
		      \]
		      Therefore,
		      \[
			      S(f + g, \mathcal D) \leq S(f, \mathcal D) + S(g, \mathcal D)
		      \]
		      Now, consider two dissections \(\mathcal D_1, \mathcal D_2\).
		      Now,
		      \[
			      I^\star(f + g) \leq S(f + g, \mathcal D_1 \cup \mathcal D_2) \leq S(f, \mathcal D_1 \cup \mathcal D_2) + S(g, \mathcal D_1 \cup \mathcal D_2) \leq S(f, \mathcal D_1) + S(g, \mathcal D_2)
		      \]
		      We can then fix \(\mathcal D_1\) and take the infimum over \(\mathcal D_2\) to get
		      \[
			      I^\star(f + g) \leq S(f, \mathcal D_1) + I^\star(g)
		      \]
		      Taking the infimum over \(\mathcal D_1\) gives
		      \[
			      I^\star(f + g) \leq I^\star(f) + I^\star(g) = \int f + \int g
		      \]
		      A completely similar argument will show that
		      \[
			      I_\star(f + g) \geq \int f + \int g
		      \]
		      Combining this, \(f+g\) must be integrable, since \(I^\star(f + g) \geq I_\star(f + g)\).
		      This integral is then exactly \(\int f + \int g\).
		      \setcounter{enumi}{3}
		\item Consider first \(f_+(x) = \max(f(x), 0)\).
		      We want to show that \(f_+\) is integrable.
		      We can check that
		      \[
			      \sup_{[x_{j-1}, x_j]}f_+ - \inf_{[x_{j-1}, x_j]}f_+ \leq \sup_{[x_{j-1}, x_j]}f - \sup_{[x_{j-1}, x_j]}f
		      \]
		      We know that given \(\varepsilon > 0\), there exists \(\mathcal D\) such that
		      \[
			      S(f, \mathcal D) - s(f, \mathcal D) < \varepsilon
		      \]
		      Hence,
		      \[
			      S(f_+, \mathcal D) - s(f_+, \mathcal D) \leq S(f, \mathcal D) - s(f, \mathcal D) < \varepsilon
		      \]
		      Therefore \(f_+\) is integrable.
		      But \(\abs{f} = 2f_+ - f\), hence \(\abs{f}\) is integrable by properties (2) and (3).
		      Since \(-\abs{f} \leq f \leq \abs{f}\), we can use monotonicity from (1) to find that
		      \[
			      \abs{\int f} \leq \int \abs{f}
		      \]
		      as claimed.
		\item Let \(f\) be integrable and positive.
		      Then we can check that
		      \[
			      \sup_{[x_{j-1}, x_j]} f^2 = \qty(\underbrace{\sup_{[x_{j-1}, x_j]} f}_{M_j})^2;\quad \inf_{[x_{j-1}, x_j]} f^2 = \qty(\underbrace{\inf_{[x_{j-1}, x_j]} f}_{m_j})^2
		      \]
		      Then,
		      \begin{align*}
			      S(f^2, \mathcal D) - s(f^2, \mathcal D) & = \sum_{j=1}^n (x_j - x_{j-1})(M_j^2 - m_j^2)        \\
			                                              & = \sum_{j=1}^n (x_j - x_{j-1})(M_j - m_j)(M_j + m_j)
		      \end{align*}
		      The function \(f\) is bounded by some constant \(k\), therefore the bracket \((M_j + m_j)\) is bounded by \(2k\), which gives
		      \[
			      S(f^2, \mathcal D) - s(f^2, \mathcal D) \leq 2k\qty(S(f, \mathcal D) - s(f, \mathcal D))
		      \]
		      So \(f^2\) is integrable.
		      Now, considering any \(f\), \(\abs{f} \geq 0\) is a non-negative integrable function.
		      Since \(f^2 = \abs{f^2}\), we deduce that \(f^2\) is integrable for any integrable \(f\).
		      Finally, for \(fg\), note that
		      \[
			      4fg = (f + g)^2 - (f - g)^2
		      \]
		      The right hand side is integrable, so the left hand side is integrable.
	\end{enumerate}
\end{proof}
